package com.gitee.wsl.net.server.role.login

import com.gitee.wsl.net.server.role.admin.SessionUser
import com.gitee.wsl.net.server.role.admin.checkRoleAuth
import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call
import io.ktor.server.response.respond
import io.ktor.server.routing.Route
import io.ktor.server.routing.delete
import io.ktor.server.sessions.clear
import io.ktor.server.sessions.sessions

fun Route.logout() {
    delete("/logout") {
        // check role
        call.checkRoleAuth()
        // act
        call.sessions.clear<SessionUser>()
        // response
        call.respond(HttpStatusCode.OK)
    }
}